package com.bawan.hrm.dao.impl;


import com.bawan.hrm.dao.PermissionDAO;
import com.bawan.hrm.model.Menu;
import com.bawan.hrm.model.Permission;

import java.util.List;

public class PermissionDAOImpl extends BaseDAO implements PermissionDAO {

    @Override
    public List<Permission> findByMnueId(Integer menuId) {
        Menu menu = new Menu();
        menu.setMenuId(menuId);
        return super.findByProperty(Permission.class, "menu", menu);
    }

    @Override
    public Permission findByPer(Integer[] values) {
        String hql = "FROM Permission WHERE perId = ? AND menu.menuId = ?";
        List<Permission> pers = this.findByHQLAndValue(hql, values);
        if (pers.size() > 0) {
            return pers.get(0);
        }
        return null;
    }

    @Override
    public Permission findByMenuIdAndFunction(Integer menuId, int i) {
        String hql = "FROM Permission WHERE menu.menuId = ? AND perFunction = ?";
        List<Permission> permission = this.findByHQLAndValue(hql, menuId, i);
        if (permission.size() > 0) {
            return permission.get(0);
        }
        return null;
    }


}
